package com.apes.exception;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.soe.annotations.State;
import com.apes.framework.plugin.soe.annotations.States;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = MessageTopic.CONST_TABLE_NAME)
public class MessageTopic extends BaseModel {
    public final static String CONST_TABLE_NAME = "message_topic";

    @Id
    @Column(name = "id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "消息订阅主题")
    private String id;

    @States(name = "主题类型", values = {
            @State(id = "ESB", name = "ESB"),
            @State(id = "OutBox", name = "OutBox"),
            @State(id = "MQ", name = "MQ")})
    @Column(name = "topic_type", length = 64, nullable = false)
    @Comment("主题类型")
    private String topicType;

    @Column(name = "topic", length = 128, nullable = false)
    @Comment("主题")
    private String topic;

    @Column(name = "description", length = 500)
    @Comment("描述")
    private String description;

    @Column(name = "aggregate_type", length = 500)
    @Comment("业务模型")
    private String aggregateType;

    @ManyToOne(optional = false)
    @JoinColumn(name = "message_subscriber", referencedColumnName = "id")
    @Comment("消息订阅者")
    private MessageSubscriber messageSubscriber;

}
